
use processed/RPImicro,clear
forvalues x = 1/17	 {
gen b`x' = s_RPI_`x'
drop if b`x' ==.
}
drop if I ==.
drop if I < 0
 
** Young
*tabstat agehd, stats(n mean median min max)
gen flag_child = 0 
replace flag_child = 1 if numhhkid > 1
gen flag_married = 0 
replace flag_married = 1 if marstat != 1 
gen flag_work = 0
replace flag_work = 1 if emppos !=2

*gen flag_agehd = 0 
*replace flag_agehd = 1 if agehd > 50	
tabstat I  if datayear ==2017, by(emppos) stats(n mean median min max)


forvalues p = 0/1  {

preserve 
*keep if penflag == 1`p'
keep if flag_married == `p'


gen logI = log(I)
gen logI2 = log(I)*log(I)
gen logI3 = log(I)*log(I)*log(I)
keep if I > 0
qui forvalues x = 1/17	 {
keep if b`x' <1 
keep if b`x' > -0.00001 
}

qui forvalues x = 1/17	 {
	reg b`x' logI  logI2  if datayear ==1974 , vce(robust)
	predict tmp if e(sample), xb 
*	replace tmp =0 if tmp < 0
	gen b`x'_hat = tmp
	drop tmp
}



qui forvalues t = 1975/2017 {

qui forvalues x = 1/17	 {
	reg b`x' logI  logI2  if datayear ==`t' , vce(robust)
	predict tmp if e(sample), xb 
*	replace tmp =0 if tmp < 0
	replace b`x'_hat = tmp if datayear == `t'
	drop tmp
}


  
}

keep datayear I b1_hat b2_hat b3_hat b4_hat b5_hat b6_hat b7_hat b8_hat b9_hat b10_hat b11_hat b12_hat b13_hat b14_hat b15_hat b16_hat b17_hat weight caseno
duplicates drop caseno datayear,force
drop caseno

outsheet using DataforMatlab\UK_Budget_married`p'.csv, comma replace nonames

restore 

}
